﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmartMap.Data.Database;

namespace SmartMap.Data.DataAccess
{
    public class ComponentData
    {
        public static List<Component> GetComponentsByAdminID(int AdminID)
        {
            CDataDataContext context = new CDataDataContext();
            // get ids
            int[] componentIds = (from comp_id in context.AdminXComponents
                               where comp_id.AdminID == AdminID
                               select comp_id.ComponentID).ToArray();
            //get matched components
            var components = from comp in context.Components
                             where componentIds.Contains(comp.ComponentId)
                             select comp;

            return components.ToList();
        }
    }
}
